package com.tarena.lbs.basic.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 区域管理
 */
@Tag(name = "区域服务", description = "区域服务")
@Slf4j
@RestController
@RequestMapping("/admin/basic/area")
public class AreaController {
	
	@Autowired
	private AreaService areaService;
	
	/**
	 * 查询省级地区列表
	 *
	 * @return 省级地区列表
	 */
	@Operation(summary = "查询省级地区列表")
	@GetMapping("/queryList")
	public Result<List<AreaVO>> queryProvinces() {
		log.debug(">>>查询省级地区列表服务");
		List<AreaVO> list = areaService.queryProvinces();
		return new Result<>(list);
	}
	
	
	/**
	 * 查询地市列表
	 *
	 * @param parentId 父级ID
	 * @return 地市列表
	 */
	@Operation(summary = "查询地市列表")
	@GetMapping("/{parentId}/children")
	public Result<List<AreaVO>> queryCities(@PathVariable("parentId") Long parentId) {
		log.debug(">>>查询地市列表服务，parentId：{}", parentId);
		List<AreaVO> list = areaService.queryCities(parentId);
		return new Result<>(list);
	}
	
	
	/**
	 * 查询地市树列表
	 *
	 * @return 地市树列表
	 */
	@Operation(summary = "查询地市树列表")
	@GetMapping("/tree")
	public Result<List<AreaVO>> queryCityTree() {
		log.debug(">>>查询地市树服务");
		List<AreaVO> list = areaService.queryCityTree();
		return new Result<>(list);
	}
	
}
